<?php
header("Content-type: text/html; charset=utf-8");
error_reporting(E_ALL);
ini_set('display_errors',1);
set_time_limit(0);
include_once dirname(dirname(dirname(__FILE__))) . '/mgtv_init.php';
include_once dirname(dirname(__FILE__)) . '/init.php';

$db_r = nn_get_db(NL_DB_READ);
$db_w = nn_get_db(NL_DB_WRITE);
$file_str = file_get_contents('checkmedia.log');
$vods = explode("|", $file_str);
foreach($vods as $vod){
	$vod_arr = explode(":", $vod);
	$vod_name = $vod_arr[0];
	
	
	$vod_indexs = $vod_arr[1];
	$vod_sql = "select * from nns_vod where nns_name='$vod_name'";
	$vod_info = nl_db_get_one($vod_sql, $db_r);
	if(is_array($vod_info)&&$vod_info!=null){		
		$indexs = explode(',', $vod_indexs);
		echo $vod_name;
		foreach ($indexs as $index) {			
			$index_sql = "select * from nns_vod_index where nns_vod_id='{$vod_info['nns_id']}' and nns_index='$index'";
			$vod_index_info = nl_db_get_one($index_sql, $db_r);	
			if(is_array($vod_index_info)&&$vod_index_info!=null){
				//echo '分集完整<br/>';
				//continue;
				$sql = "select * from nns_mgtvbk_c2_task where nns_ref_id='{$vod_index_info['nns_id']}' and nns_org_id='fjyd' and nns_type='index' and nns_vod_id='{$vod_index_info['nns_vod_id']}'";
				$c2_task_info = nl_db_get_one($sql, $db_r);
				if(empty($c2_task_info['nns_id'])){
					$data = array(
						'nns_id'=>np_guid_rand('fjyd'),
						'nns_type'=>'media',
						'nns_name'=>$vod_index_info['nns_name'],
						'nns_ref_id'=>$vod_index_info['nns_id'],
						'nns_org_id'=>'fjyd',
						'nns_action'=>'add',
						'nns_status'=>1,
						'nns_create_time'=>date('Y-m-d H:i:s'),
						'nns_src_id'=>$vod_index_info['nns_vod_id'],
					);
					//i_write_log_core(var_export($data,true));
					$re = nl_db_insert($db_w, 'nns_mgtvbk_c2_task', $data);
				}
				continue;			
				// $media_sql = "select * from nns_vod_media where nns_vod_id='{$vod_info['nns_id']}' and nns_vod_index=$index and nns_vod_index_id='{$vod_index_info['nns_id']}'";
				// $vod_media_info = nl_db_get_one($media_sql, $db_r);
				// if(is_array($vod_media_info)&&$vod_media_info!=null){
					// $clip_sql = "select * from nns_mgtvbk_clip_task where nns_org_id='fjyd' and nns_video_id='{$vod_info['nns_id']}' and nns_video_index_id='{$vod_media_info['nns_vod_index_id']}'";
					// $clip_task_info = nl_db_get_one($clip_sql, $db_r);
					// if(is_array($clip_task_info)&&$clip_task_info!=null){
						// //clip_task_model::restart_task($clip_task_info['nns_id'],0);
						// //echo "$vod_name  $index 切片任务状态: ".$clip_task_info['nns_state']."<br/>";
					// }else{
						// $task_info = array();
						// $task_info['nns_video_type'] = 0;
						// $task_info['nns_video_id'] = $vod_media_info['nns_vod_id'];
						// $task_info['nns_video_index_id'] = $vod_media_info['nns_vod_index_id'];
						// $task_info['nns_index'] = $index;
						// clip_task_model::add_task($task_info);
						// //echo "$vod_name  $index 没有切片任务"."<br/>";
					// }
				// }else{
					// //echo "$vod_name  $index 缺失片源"."<br/>";
				// }				
			}else{
				echo "$index,";
			}
		}
		echo "<br/>";
	}else{
		echo "$vod_name  缺失"."<br/>";
	}	
	//die;
}
